package cn.iocoder.yudao.module.infra.dal.mysql.infotablecollect;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.infotablecollect.InfoTableCollectDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.infra.controller.admin.infotablecollect.vo.*;

/**
 * 基础资料表汇总 Mapper
 *
 * @author lry
 */
@Mapper
public interface InfoTableCollectMapper extends BaseMapperX<InfoTableCollectDO> {

    default PageResult<InfoTableCollectDO> selectPage(InfoTableCollectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InfoTableCollectDO>()
                .eqIfPresent(InfoTableCollectDO::getDataSourceConfigId, reqVO.getDataSourceConfigId())
                .eqIfPresent(InfoTableCollectDO::getScene, reqVO.getScene())
                .likeIfPresent(InfoTableCollectDO::getTableName, reqVO.getTableName())
                .likeIfPresent(InfoTableCollectDO::getTableComment, reqVO.getTableComment())
                .eqIfPresent(InfoTableCollectDO::getRemark, reqVO.getRemark())
                .likeIfPresent(InfoTableCollectDO::getModuleName, reqVO.getModuleName())
                .likeIfPresent(InfoTableCollectDO::getBusinessName, reqVO.getBusinessName())
                .likeIfPresent(InfoTableCollectDO::getClassName, reqVO.getClassName())
                .eqIfPresent(InfoTableCollectDO::getClassComment, reqVO.getClassComment())
                .eqIfPresent(InfoTableCollectDO::getAuthor, reqVO.getAuthor())
                .eqIfPresent(InfoTableCollectDO::getTemplateType, reqVO.getTemplateType())
                .eqIfPresent(InfoTableCollectDO::getFrontType, reqVO.getFrontType())
                .eqIfPresent(InfoTableCollectDO::getParentMenuId, reqVO.getParentMenuId())
                .betweenIfPresent(InfoTableCollectDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InfoTableCollectDO::getId));
    }

    default List<InfoTableCollectDO> selectList(InfoTableCollectExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<InfoTableCollectDO>()
                .eqIfPresent(InfoTableCollectDO::getDataSourceConfigId, reqVO.getDataSourceConfigId())
                .eqIfPresent(InfoTableCollectDO::getScene, reqVO.getScene())
                .likeIfPresent(InfoTableCollectDO::getTableName, reqVO.getTableName())
                .eqIfPresent(InfoTableCollectDO::getTableComment, reqVO.getTableComment())
                .eqIfPresent(InfoTableCollectDO::getRemark, reqVO.getRemark())
                .likeIfPresent(InfoTableCollectDO::getModuleName, reqVO.getModuleName())
                .likeIfPresent(InfoTableCollectDO::getBusinessName, reqVO.getBusinessName())
                .likeIfPresent(InfoTableCollectDO::getClassName, reqVO.getClassName())
                .eqIfPresent(InfoTableCollectDO::getClassComment, reqVO.getClassComment())
                .eqIfPresent(InfoTableCollectDO::getAuthor, reqVO.getAuthor())
                .eqIfPresent(InfoTableCollectDO::getTemplateType, reqVO.getTemplateType())
                .eqIfPresent(InfoTableCollectDO::getFrontType, reqVO.getFrontType())
                .eqIfPresent(InfoTableCollectDO::getParentMenuId, reqVO.getParentMenuId())
                .betweenIfPresent(InfoTableCollectDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InfoTableCollectDO::getId));
    }

    default InfoTableCollectDO selectByTableNameAndDataSourceConfigId(String tableName, Long dataSourceConfigId) {
        return selectOne(InfoTableCollectDO::getTableName, tableName,
                InfoTableCollectDO::getDataSourceConfigId, dataSourceConfigId);
    }

    default List<InfoTableCollectDO> selectListByDataSourceConfigId(Long dataSourceConfigId) {
        return selectList(InfoTableCollectDO::getDataSourceConfigId, dataSourceConfigId);
    }

    /**
     * 根据名称查询可用的元素表
     * @param tableName
     * @return
     */
    default InfoTableCollectDO selectByTableName(String tableName) {
        return selectOne(InfoTableCollectDO::getTableComment, tableName,
                InfoTableCollectDO::getDeleted, 0);
    }



}
